package cn.tqfeiyang.smartadmin.system.controller;

import cn.tqfeiyang.smartadmin.commons.logging.OperationLog;
import cn.tqfeiyang.smartadmin.commons.response.ApiResult;
import cn.tqfeiyang.smartadmin.system.request.UserLoginDTO;
import cn.tqfeiyang.smartadmin.system.request.UserQueryDTO;
import cn.tqfeiyang.smartadmin.system.response.UserLoginVO;
import cn.tqfeiyang.smartadmin.system.service.ConfigService;
import cn.tqfeiyang.smartadmin.system.service.SessionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 会话控制器
 *
 * @author tqfeiyang
 * @since 2024-08-23
 */
@RestController
@Validated
@RequestMapping("/api/system/session")
@Tag(name = "公共/会话")
public class SessionController {

    /**
     * 会话服务
     */
    @Resource
    private SessionService sessionService;

    /**
     * 用户登录
     *
     * @param dto 请求数据
     * @return 用户信息
     */
    @OperationLog
    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public ApiResult<UserLoginVO> login(@RequestBody @Validated UserLoginDTO dto) {
        return ApiResult.success(sessionService.login(dto));
    }

    /**
     * 用户登出
     */
    @OperationLog
    @PostMapping("/logout")
    @Operation(summary = "用户登出")
    public ApiResult<String> logout() {
        sessionService.logout();
        return ApiResult.success();
    }

}
